//生成菜单
var menuItem1 = Vue.extend({
	name: 'menu-item',
	props:{item:{}},
	template:[
	          '<li>',
				'<a v-if="item.type === 0" href="#">',
					'<i v-if="item.icon != null" :class="item.icon"></i>',
					'<span class="nav-label">{{item.name}}</span>',
					'<span class="fa arrow"></span>',
				'</a>',
				'<ul v-if="item.type === 0" class="nav nav-second-level">',
					'<menu-item :item="item" v-for="item in item.list"></menu-item>',
				'</ul>',
				'<a v-if="item.type === 1" class="J_menuItem  agu" :href="item.url">',
					'{{item.name}}',
				'</a>',
	          '</li>'
	].join('')
});

//注册菜单组件
Vue.component('menuItem',menuItem1);

var vm = new Vue({
	el:'#wrapper',
	data:{
		user:{},
		menuList:{},
		main:"sys/main.html",
		password:'',
		newPassword:'',
        navTitle:"控制台"
	},
    mounted: function () {

    },
	methods: {
		init:function () {


        },
		getMenuList: function (event) {
			$.getJSON("api/auth/menu?_"+$.now(), function(r){
				vm.menuList = r.data.menuList;
                window.permissions = r.data.permissions;
                vm.$nextTick( function (){
                    $('#side-menu').metisMenu();
                    $('.J_menuItem').on('click', $navtabs.menuItem);
            	})
			});
		},
		getUser: function(){
			$.getJSON("api/auth/info?_"+$.now(), function(r){
				vm.user = r.data;
			});
		},
		updatePassword: function(){
			layer.open({
				type: 1,
				skin: 'layui-layer-molv',
				title: "修改密码",
				area: ['550px', '270px'],
				shadeClose: false,
				content: jQuery("#passwordLayer"),
				btn: ['修改','取消'],
                yes: function (index) {
					var data = "password="+vm.password+"&newPassword="+vm.newPassword;
					$.ajax({
						type: "POST",
					    url: "api/auth/password",
					    data: data,
					    dataType: "json",
					    success: function(result){
							if(result.code == 0){
								layer.close(index);
								layer.alert('修改成功', function(index){
									location.reload();
								});
							}else{
								layer.alert(result.message);
							}
						}
					});
	            },
                btn2: function(index){
                   layer.close(index);
            	}
			});
		}
	},
	created: function(){
		this.getMenuList();
		this.getUser();
	},
	updated: function(){
		//路由
	}
});

